﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Services;
using ProcessDB;
using System.Web.Services.Protocols;
using System.Text;

namespace WebService1
{
    /// <summary>
    /// Summary description for GetInfo
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    public class GetInfo : System.Web.Services.WebService
    {
        public AuthHeader Authentication;

        GetDB YGetInfo = new GetDB();
        [WebMethod]
        [SoapHeader("Authentication", Required = true)]
        public string GetNickName(int ID)
        {
            if (Authentication.Username == "yugioh" &&
                Authentication.Password == "admin123")
            {
                return YGetInfo.GetNickName(ID);
            }
            else 
                return "";
        }

        [WebMethod]
        [SoapHeader("Authentication", Required = true)]
        public string GetCardsOfPlayer(int ID)
        {
            if (Authentication.Username == "yugioh" &&
               Authentication.Password == "admin123")
            {
                return YGetInfo.GetCardsOfPlayer(ID);
            }
            else
                return "";
        }

        [WebMethod]
        [SoapHeader("Authentication", Required = true)]
        public string GetAllTable(int RoomID)
        {
            if (Authentication.Username == "yugioh" &&
            Authentication.Password == "admin123")
            {
                try
                {
                    StringBuilder str = new StringBuilder();
                    foreach (var item in YGetInfo.GetAllTable(RoomID))
                    {
                        str.AppendFormat("{0}\n", item);
                    }
                    return str.ToString();
                }
                catch(Exception ex)
                {
                    return ex.Message;
                    return "";
                }
            }
            else
                return "";
        }
        [WebMethod]
        [SoapHeader("Authentication", Required = true)]
        public string GetAllRoom()
        {
            if (Authentication.Username == "yugioh" &&
            Authentication.Password == "admin123")
            {
                try{
                    StringBuilder str = new StringBuilder();
                    foreach (var item in YGetInfo.GetAllRoom())
                    {
                        str.AppendFormat("{0}\n", item);
                    }
                    return str.ToString(); 
                }
                catch
                {
                    return "";
                }
            }
            else
                return "";
        }
        [WebMethod]
        [SoapHeader("Authentication", Required = true)]
        public string GetAllFriend(int UserID)
        {
            if (Authentication.Username == "yugioh" &&
            Authentication.Password == "admin123")
            {
                try
                {
                    StringBuilder str = new StringBuilder();
                    foreach (var item in YGetInfo.GetAllFriend(UserID))
                    {
                        str.AppendFormat("{0}\n", item);
                    }
                    return str.ToString();
                }
                catch(Exception ex) {
                    return ex.Message;
                    return ""; 
                }
            }
            else
                return "";
        }
        [WebMethod]
        [SoapHeader("Authentication", Required = true)]
        public string GetAllUser(int RoomID)
        {
            if (Authentication.Username == "yugioh" &&
            Authentication.Password == "admin123")
            {
                try
                {
                    StringBuilder str = new StringBuilder();
                    foreach (var item in YGetInfo.GetAllUser(RoomID))
                    {
                        str.AppendFormat("{0}\n", item);
                    }
                    return str.ToString();
                }
                catch { return ""; }
            }
            else
                return "";
        }
    }
}
